# Contributor: Galen Abell <galen@galenabell.com>
# Maintainer: Galen Abell <galen@galenabell.com>
pkgname=lua-editorconfig
_pkgname=editorconfig-core-lua
_rockname=editorconfig-core
pkgver=0.3.0
pkgrel=0
pkgdesc="EditorConfig Core bindings for Lua"
url="https://github.com/editorconfig/editorconfig-core-lua"
arch="all"
license="BSD-2-Clause"
makedepends="cmake editorconfig-dev"
options="!check"  # no tests
source="$_pkgname-$pkgver.tar.gz::https://github.com/editorconfig/editorconfig-core-lua/archive/v$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

_luaversions="5.2 5.3 5.4"  # depends on lua5.2+
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev"
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

build() {
	local lver; for lver in $_luaversions; do
		mkdir -p "$builddir"/build-$lver
		cd "$builddir"/build-$lver

		msg "Building against Lua $lver..."
		cmake \
			-DCMAKE_INSTALL_PREFIX=/usr \
			-DCMAKE_INSTALL_LIBDIR=lib \
			-DBUILD_SHARED_LIBS=True \
			-DCMAKE_BUILD_TYPE=None \
			-DLUA_INCLUDE_DIR="$(pkg-config --variable=includedir lua$lver)" \
			-DLUA_LIBRARIES="$(pkg-config --variable=libdir lua$lver)" \
			$CMAKE_CROSSOPTS ..

		make
	done
}

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc (for Lua $lver)"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"
	local install_cmod=$(pkg-config --variable=INSTALL_CMOD lua$lver)
	local rockdir="$subpkgdir/usr/lib/luarocks/rocks-$lver/$_rockname/$pkgver-1"

	install -D -m 755 "$builddir"/build-$lver/editorconfig.so \
		"$subpkgdir"/$install_cmod/editorconfig.so

	mkdir -p "$rockdir"
	echo 'rock_manifest = {}' > "$rockdir"/rock_manifest
}

sha512sums="9d9afbfc5e6a2b352eb5d4066111f34836fb6eefb0363173d6aa55078be2be2129f9d1c9d9bcef85899b99bf332861de30046d9a2bc27a96b92d4cf2681aea05  editorconfig-core-lua-0.3.0.tar.gz"
